From: Giovanni Campagna Date: Fri, 27 Apr 2012 23:25:12 +0000 (+0200) Subject: NetworkAgent: disallow multiple requests for the same connection/setting X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~6604 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=e6087efb40cd092cd343eb9397cec27419f38c1b;p=gnome-shell.git NetworkAgent: disallow multiple requests for the same connection/setting It doesn't make sense to have multiple requests for the same connection/setting combination at the same time, since we would be asking the user twice for the same password. Instead, report cancellation to NetworkManager if this happens. Note that does make sense to have multiple requests in sequence though (they could have different flags), but this is not affected. https://bugzilla.gnome.org/show_bug.cgi?id=674961 --- diff --git a/src/shell-network-agent.c b/src/shell-network-agent.c index a667bfa78..ca60539f7 100644 --- a/src/shell-network-agent.c +++ b/src/shell-network-agent.c @@ -76,6 +76,26 @@ shell_agent_request_free (gpointer data) g_slice_free (ShellAgentRequest, request); } +static void +shell_agent_request_cancel (ShellAgentRequest *request) +{ + GError *error; + ShellNetworkAgent *self; + + self = request->self; + + error = g_error_new (NM_SECRET_AGENT_ERROR, + NM_SECRET_AGENT_ERROR_AGENT_CANCELED, + "Canceled by NetworkManager"); + request->callback (NM_SECRET_AGENT (self), request->connection, + NULL, error, request->callback_data); + + g_signal_emit (self, signals[SIGNAL_CANCEL_REQUEST], 0, request->request_id); + + g_hash_table_remove (self->priv->requests, request->request_id); + g_error_free (error); +} + static void shell_network_agent_init (ShellNetworkAgent *agent) { @@ -341,6 +361,17 @@ shell_network_agent_get_secrets (NMSecretAgent *agent, ShellAgentRequest *request; NMSettingConnection *setting_connection; const char *connection_type; + char *request_id; + + request_id = g_strdup_printf ("%s/%s", connection_path, setting_name); + if ((request = g_hash_table_lookup (self->priv->requests, request_id)) != NULL) + { + /* We already have a request pending for this (connection, setting) + * Cancel it before starting the new one. + * This will also free the request structure and associated resources. + */ + shell_agent_request_cancel (request); + } setting_connection = nm_connection_get_setting_connection (connection); connection_type = nm_setting_connection_get_connection_type (setting_connection); @@ -371,7 +402,7 @@ shell_network_agent_get_secrets (NMSecretAgent *agent, else request->vpn_entries = NULL; - request->request_id = g_strdup_printf ("%s/%s", connection_path, setting_name); + request->request_id = request_id; g_hash_table_replace (self->priv->requests, request->request_id, request); if ((flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW) || @@ -490,30 +521,22 @@ shell_network_agent_cancel_get_secrets (NMSecretAgent *agent, { ShellNetworkAgent *self = SHELL_NETWORK_AGENT (agent); ShellNetworkAgentPrivate *priv = self->priv; + gchar *request_id; + ShellAgentRequest *request; - gchar *request_id = g_strdup_printf ("%s/%s", connection_path, setting_name); - ShellAgentRequest *request = g_hash_table_lookup (priv->requests, request_id); - GError *error; + request_id = g_strdup_printf ("%s/%s", connection_path, setting_name); + request = g_hash_table_lookup (priv->requests, request_id); + g_free (request_id); if (!request) { /* We've already sent the result, but the caller cancelled the * operation before receiving that result. */ - g_free (request_id); return; } - error = g_error_new (NM_SECRET_AGENT_ERROR, - NM_SECRET_AGENT_ERROR_AGENT_CANCELED, - "Canceled by NetworkManager"); - request->callback (agent, request->connection, NULL, error, request->callback_data); - - g_signal_emit (self, signals[SIGNAL_CANCEL_REQUEST], 0, request_id); - - g_hash_table_remove (priv->requests, request_id); - g_free (request_id); - g_error_free (error); + shell_agent_request_cancel (request); } /************************* saving of secrets ****************************************/